package offer;

/**
 * @Author SSK
 * @Date Created in 22:44 2019/8/4
 * @Description 构建乘积数组
 * @Version 1.0
 */
public class T52 {
    public int[] multiply(int[] A) {
        if (A==null||A.length<=1) {
            return A;
        }
        int b[] =new int[A.length];
        b[A.length-1] = A[A.length-1];
        for (int i = A.length-2; i >=0 ; i--) {
             b[i] = b[i+1] * A[i];
        }
        int temp = 1;
        for (int i = 0; i < b.length-1; i++) {
             b[i] = b[i+1]*temp;
             temp*=A[i];
        }
        b[A.length-1] = temp;
        return b;
    }
    public static void main ( String[] args) {
        new T52().multiply(new int[]{1,2,3,4,5});

    }
}
